<?php

namespace app\admin\model\shopro\store;

use fast\Tree;
use think\Model;
use traits\model\SoftDelete;

class Recharge extends Model
{

    use SoftDelete;



    // 表名
    protected $name = 'store_money';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

   public function getTypeAttr($val,$data){
       if (!empty($val)){
           if($val == 'zhichu'){
               $val = '支出';
           }else{
               $val = '增加';
           }
       }
       return $val;
   }
    public function getOriginAttr($val,$data){
        if (!empty($val)){
            switch ($val){
                case "admin":
                    $val= '后台管理员增加';
                    break;
                case "admin_refund":
                    $val= '后台管理员减少';
                    break;
                case "goods":
                    $val= '确认收货增加';
                    break;
                case "hexiao":
                    $val= '核销完成增加';
                    break;
                case "goods_refund":
                    $val= '确认退货减少';
                    break;
                case "scan":
                    $val= '扫码订单增加';
                    break;
                case "scan_refund":
                    $val= '扫码订单退款';
                    break;
                default :
                    $val = "确认收货增加";
                    break;
            }
        }
        return $val;
    }
    public function getCreateTimeAttr($val,$data)
    {
         if(is_numeric($val)){
             return date('Y-m-d H:i:s',$val);
         }else{
             return $val;
         }
    }
    public function store(){
        return $this->belongsTo(\app\admin\model\shopro\store\Store::class, 'store_id', 'id');
    }
}
